package gui_layer;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

@SuppressWarnings("serial")
public abstract class UniversalAddWindow extends UniversalTableWindow
{
	protected JTextField search_field;
	protected JButton btnAdd;
	protected JLabel search_lbl;
	protected JButton btnCancel;

	public UniversalAddWindow()
	{
		super();
		make_btns();
		make_search();
		set_table_params();
	}
	
	private void make_btns()
	{
		float[] values = Color.RGBtoHSB(255, 104, 0, null);
		btnAdd = new JButton("Add");
		btnAdd.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		btnAdd.setForeground(Color.WHITE);
		btnAdd.setBackground(Color.getHSBColor(values[0], values[1], values[2]));
		btnAdd.setContentAreaFilled(false);
		btnAdd.setOpaque(true);
		btnAdd.setBorder(new RoundedCornerBorder());
		btnAdd.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent arg0)
			{
				set_or_add();
				
			}
		});
		additional_button_panel.add(btnAdd);
		
		btnCancel = new JButton("Cancel");
		btnCancel.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		btnCancel.setForeground(Color.WHITE);
		btnCancel.setBackground(Color.getHSBColor(values[0], values[1], values[2]));
		btnCancel.setContentAreaFilled(false);
		btnCancel.setOpaque(true);
		btnCancel.setBorder(new RoundedCornerBorder());
		btnCancel.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent arg0)
			{
				dispose();
				
			}
		});
		option_button_panel.add(btnCancel);
	}
	
	private void make_search()
	{
		search_lbl = new JLabel("Name");
		search_lbl.setForeground(Color.WHITE);
		search_lbl.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		search_set_panel.add(search_lbl);
		
		search_field = new JTextField();
		search_field.setBorder(new RoundedCornerBorder());
		search_field.setFont(new Font("Helvetica Neue", Font.BOLD, 11));
		search_field.addKeyListener(new KeyAdapter()
		{			
			@Override
			public void keyReleased(KeyEvent arg0)
			{
				dynamically_search();
			}
			
		});
		search_field.addFocusListener(new FocusAdapter()
		{
			public void focusGained(FocusEvent e)
			{
				show_non_deleted();
			}
		});
		search_set_panel.add(search_field);
		search_field.setColumns(14);
	}
	
	private void set_table_params()
	{
		
		table.addMouseListener(new MouseAdapter()
		{
			public void mouseClicked(MouseEvent e)
			{
				if (e.getClickCount() == 2)
				{
					set_or_add();
				}
			}
		});
	}
	
	protected abstract void set_or_add();
	
	protected abstract void dynamically_search();
	
	protected abstract void show_non_deleted();

}
